package com.hotel.project.common.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * TODO
 *
 * @author: peng.ni
 * @date: 2022/04/13
 */
public class MD5Utils {
    private static final int num = 32;
    private static final String str = "0";

    public static String md5(String pwd) {
        byte[] secretBytes = null;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(pwd.getBytes());
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e.getMessage());
        }
        String md5code = new BigInteger(1, secretBytes).toString(16);
        for (int i = 0; i < num - md5code.length(); i++) {
            md5code = str + md5code;
        }
        return md5code;
    }
}
